<?php //Отписка от рассылки
/*DEE_DESC
$templ['title']='Отписка от рассылки';
//DEE_DESC_END*/

	$unsubscr	= isset( $_GET['unsubscr'] )	? $_GET['unsubscr']	: '';
	$zakaz		= isset( $_GET['zakaz'] )		? $_GET['zakaz']	: '-';
	
	if( !$unsubscr )
		successRedirect( array( 'url' => '/' ) );
		
	
	$view->gText .= 
		$view->printH1('s').
		'<div class="text2">
			'.$view->text1.'
			<button class="global-button green-bg unsubscription" id="'.$unsubscr.'">Отписаться от рассылки</button>
			<input type="hidden" class="successful_mess" value="'.$view->text2.'"/>
			<input type="hidden" class="zakaz" value="'.$zakaz.'"/>
		</div>'
		.$load->block('submit_form_loader');

	
	
	$view->js_on_load[] = '
		$(document).ready(function(){
			$(".unsubscription").click(function(){
				$(this).attr("disabled","disabled");
				var text2 = $(".text2");
				var loader = $(".submit_form_loader");
				var response_div = $(".response");
				var errors_div = $(".errors");
				var successful_div = $(".successful_checkout");
				loader.show();
				response_div.hide();
				
				$.ajax({
					cache   : false,
					dataType: "json",
					type    : "POST",
					url     : "/?ajax=unsubscription",
					data    : { "unsubscr" : $(this).attr("id"), "successful" : $(".successful_mess").val(), "zakaz" : $(".zakaz").val() },
					success : function( response ) {
						if( response.errors )
						{
							successful_div.html("").hide();
							errors_div.html( response.message ).show();
							response_div.slideDown("slow");
						}
						else
						{
							errors_div.html("").hide();
							successful_div.html( response.message ).show();
							response_div.slideDown("slow");
							text2.slideUp( 700 );
						}
						$(".unsubscription").removeAttr("disabled");
						loader.hide();
					}
				});
			});
		});';
